﻿<?php

class AdApp extends BaseApp
{
    function js()
    {
	unset($_AD_label,$AD_label);
	require_once(ROOT_PATH."/data/ad/ad_cache.php");
	$show=$_AD_label[$_GET[adid]];

	//对javascript进行特别处理
	if(eregi("<SCRIPT",$show)){
		preg_match_all("/<SCRIPT([^>]*)>(.*?)<\/SCRIPT>/is",$show,$array);
		foreach($array[1] AS $key=>$value){
			//一般联盟广告会出现这种情况
			if(eregi("src=",$value)){
				$value=str_replace("'","\'",$value);
				echo "document.write('<SCRIPT$value><\/SCRIPT>');";
			}else{
				echo $array[2][$key];
			}
		}
		$show=preg_replace("/(.*?)<SCRIPT([^>]*)>(.*?)<\/SCRIPT>(.*?)/is","\\1\\4",$show);
	}

	$show=str_replace("\n","",$show);
	$show=str_replace("\r","",$show);
	$show=str_replace("'","\'",$show);
	echo "document.write('$show');";
	exit;
    }
  
    function jump()
    {
    $db = & get_db();
	$_pre = DB_PREFIX;
	$id = $_GET[id];
	$u_id = $_GET[u_id];
	$rs=$db->get_one("SELECT * FROM {$_pre}ad_place WHERE id='$id'");
	$acodedb=unserialize($rs[adcode]);
	if($acodedb){
		$db->query("UPDATE {$_pre}ad_place SET hits=hits+1 WHERE id='$id'");
		if($u_id){
			$db->query("UPDATE {$_pre}ad_user SET u_hits=u_hits+1 WHERE u_id='$u_id'");
		}
		if($acodedb[linkurl]&&!$u_id){
			header("location:$acodedb[linkurl]");
		}else{
			$url=base64_decode($url);
			header("location:$url");
		}		
		exit;
	}
	
    }
}


?>